package com.bjpowernode.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjpowernode.springboot.entity.Character;
import com.bjpowernode.springboot.entity.CharacterVO;
import com.bjpowernode.springboot.entity.User;
import com.bjpowernode.springboot.entity.UserVO;
import com.bjpowernode.springboot.mapper.CharacterMapper;
import com.bjpowernode.springboot.mapper.UserMapper;
import com.bjpowernode.springboot.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.function.Predicate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yan
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/characterPlus")
@Api(value = "/characterPlus", description = "用色操作接口")
public class CharacterController {

    @ApiOperation(value = "根据name查询")
    @GetMapping("/get")
    public UserVO charVOByName(@RequestParam String characterName){
        return characterMapper.charVOByName(characterName);
    }
    @Autowired
    CharacterMapper characterMapper;
    @ApiOperation(value = "根据ID查询")
    @GetMapping("/getByID")
    public CharacterVO charByID(@RequestParam Integer id){
        return characterMapper.charByID(id);
    }

    @ApiOperation(value = "根据ID或名字查询")
    @GetMapping("/getByIDOrName")
    public CharacterVO charByIdOrName(@RequestParam(required = false) Integer id, @RequestParam(required = false) String characterName){
        return characterMapper.charByIdOrName(id, characterName);
    }

    @ApiOperation(value = "根据ID分页查询")
    @GetMapping("/charPage")
    public IPage<CharacterVO> charPage(@RequestParam Integer size,
                                        @RequestParam Integer current, @RequestParam Integer id){
            Page<CharacterVO> page = new Page<>();
        //设置每页条数
        page.setSize(size);
        //设置查询第几页
        page.setCurrent(current);
        IPage<CharacterVO> userIPage = characterMapper.charPage(page, id);
        return userIPage;
    }

    }
